package com.xujiang.common_plus.core;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;

import com.wang.avi.AVLoadingIndicatorView;
import com.xujiang.common_core.util.ui.UIUtils;
import com.xujiang.common_plus.R;

/**
 * @author xujiang
 * @version 2017-08-09 15:23
 */
public class CPProgressHelper {
    private AVLoadingIndicatorView mProgressBar;
    private View mLayout;

    public static CPProgressHelper with(@NonNull View view){
        View layout = view.findViewById(R.id.ek_cp_progress_layout);
        return new CPProgressHelper(layout,(AVLoadingIndicatorView) UIUtils.findViewById(view,R.id.ek_cp_progress));
    }

    public static CPProgressHelper with(@NonNull Activity activity) {
        View layout = activity.findViewById(R.id.ek_cp_progress_layout);
        return new CPProgressHelper(layout,
                (AVLoadingIndicatorView) UIUtils.findViewById(activity, R.id.ek_cp_progress));
    }

    public CPProgressHelper(AVLoadingIndicatorView progressBar) {
        mProgressBar = progressBar;
    }

    private CPProgressHelper(View layout, AVLoadingIndicatorView progressBar) {
        mLayout = layout;
        mProgressBar = progressBar;
    }

    public AVLoadingIndicatorView getProgressBar() {
        return mProgressBar;
    }

    public void visible() {
        mProgressBar.show();
        if (mLayout != null) {
            UIUtils.viewVisible(mLayout);
        }
    }

    public void gone() {
        mProgressBar.hide();
        if (mLayout != null) {
            UIUtils.viewGone(mLayout);
        }
    }


}
